package org.example.microservice.basedata.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jConfig {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("basedata")
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.example.microservice"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(parameters());// 全局配置
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .description("# Knife4j Restful APIs")
                .termsOfServiceUrl("https://doc.xiaominfo.com/")
                .contact("conggege325@qq.com")
                .version("1.0")
                .build();
    }

    private List<Parameter> parameters() {
        List<Parameter> list = new ArrayList<>();
        list.add(new ParameterBuilder()
                .name("Authorization")
                .description("Token")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build());
        return list;
    }
}
